/**
 * @author hexj
 * @desc 弹出菜单组件
 * @time 2018-06-27
 */
const app = getApp(),
  {
    $resHost
  } = app.globalData;
Component({
  properties: {},
  data: {
    list: [`${$resHost}/img/indexPage/m_z.png`, `${$resHost}/img/indexPage/m_info.png`, `${$resHost}/img/indexPage/service.png`, `${$resHost}/img/indexPage/m_share.png`, `${$resHost}/img/indexPage/m_colse.png`],
    m_m: `${$resHost}/img/indexPage/m_open.png`,
    toggle: false,
    animationData: {}
  },
  methods: {
    toggleTap(event) {
      let model = event.currentTarget.dataset.model;
      this.animationToggle({
        currentTarget: {
          dataset: {
            model: model
          }
        }
      });
    },
    actionTap(event) {
      let {
        idx
      } = event.currentTarget.dataset;
      this.triggerEvent('action', {
        idx: idx
      });
      this.animationToggle({
        currentTarget: {
          dataset: {
            model: false
          }
        }
      });
    },
    animationToggle(e) {
      let currentModel = e.currentTarget.dataset.model;
      this.animation = xhs.createAnimation({
        duration: 200,
        timingFunction: "linear",
        transformOrigin: "50% 50%",
        delay: 2
      });
      this.animation.opacity(0).rotateX(-100).step();
      this.setData({
        animationData: this.animation.export()
      });
      setTimeout(function () {
        this.animation.opacity(1).rotateX(0).step();
        this.setData({
          animationData: this.animation
        });
        this.setData({
          toggle: currentModel
        });
      }.bind(this), 200);
    }
  }
});